package com.chanceit.ssss.common;

import org.gl.GlobalVariable;
import org.json.JSONException;
import org.json.JSONObject;

public class IntentExtraDataKeyValue implements IntentExtraDataKey {
	/**
	 * 更新当前的车主信息
	 * @param userJson
	 */
	public static void updateUserInfoToIntent(String userJson) {
		try {
			JSONObject userListJosnAry = new JSONObject(userJson);
			GlobalVariable.getGlobalInstance().intent.putExtra(
					IntentExtraDataKey.USERID,
					userListJosnAry.optInt(IntentExtraDataKey.USERID));
			GlobalVariable.getGlobalInstance().intent.putExtra(
					IntentExtraDataKey.PLATE,
					userListJosnAry.optString(IntentExtraDataKey.PLATE));
			GlobalVariable.getGlobalInstance().intent.putExtra(
					IntentExtraDataKey.USEINFO, userListJosnAry.toString());
		} catch (JSONException e) {
			e.printStackTrace();
		} catch (NullPointerException e) {
			e.printStackTrace();
		}
	}

	public static JSONObject getUserInfoToIntent() {
		try {
			JSONObject userListJosnAry = new JSONObject(
					GlobalVariable.getGlobalInstance().intent
							.getStringExtra(IntentExtraDataKey.USEINFO));
			return userListJosnAry;
		} catch (JSONException e) {
			e.printStackTrace();
		} catch (NullPointerException e) {
			e.printStackTrace();
		}
		return null;
	}
	public static String getUserIdentifier() {
		try {
			JSONObject userListJosnAry = new JSONObject(
					GlobalVariable.getGlobalInstance().intent
					.getStringExtra(IntentExtraDataKey.USEINFO));
			return userListJosnAry.optString("identifier");
		} catch (JSONException e) {
			e.printStackTrace();
		} catch (NullPointerException e) {
			e.printStackTrace();
		}
		return null;
	}
}
